<?php
/**
 * Created by PhpStorm.
 * User: haobin
 * Date: 2016/10/19
 * Time: 9:22
 */
//封号列表
require('../conn.php');
require('../functions.php');
require('admin.php');
$page = $_GET['page'];
if (is_numeric($page) == false) {
    $page = 1;
    $page_1 = 1;
    $min = 0;
    $page_2 = $page + 1;
} else {
    if ($page > 1) {
        $page_2 = $page + 1;
        $min = ($page - 1) * 35;
        $page_1 = $page - 1;
    } else {
        $page_1 = 1;
        $min = 0;
        $page_2 = 2;
    }
}
$max = $page * 35;
$sql = "select DISTINCT(SUBSTRING(day,1,11)) as day from user WHERE day != 'null' GROUP BY day ORDER BY day limit {$min},{$max}";
$row = $mysql->query($sql);
?>

<?php include('head.php') ?>
<div class="container-fluid">
    <div class="row-fluid">
        <?php
        include('left.php'); ?>
        <div class="span10">
            <h1 class="page-title">用户分析</h1>
            <?php
            $all = $mysql->query("select count(*) as num from user");
            $robot = $mysql->query("select count(*) as num from user where `isrobot` = 1");
            ?>
            <h2>平台总用户数:<?=$all[0]['num']?></h2>
            <h2>机器人数：<?=$robot[0]['num']?></h2>
            <div class="well">
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane active in" id="home">
                        <div class="well">
                            <div class="pull-right">
                                <a href="analysis.php" class="btn">首页</a></button>
                                <a href="analysis.php?page=<?php echo $page_1 ?>" class="btn"
                                   style="margin-left:5px;">上一页</a>
                                <a href="analysis.php?page=<?php echo $page_2 ?>" class="btn"
                                   style="margin-left:5px;">下一页</a>
                            </div>
                            <table class="table">
                                <thead>
                                <tr>
                                    <th>注册日期</th>
                                    <th>总注册人数</th>
                                    <th>安卓注册人数</th>
                                    <th>苹果注册人数</a></th>
                                    <th>绑定微信数</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                foreach ($row as $data) {
                                    //总注册人数
                                    $count = $mysql->query("select COUNT(*) as num from `user` WHERE `day` like '{$data['day']}%'");
                                    //安卓注册人数
                                    $android = $mysql->query("select COUNT(*) as num from `user` WHERE `day` like '{$data['day']}%' and `device`='android'");
                                    //苹果注册人数
                                    $iPhone = $mysql->query("select COUNT(*) as num from `user` WHERE `day` like '{$data['day']}%' and `device`='iPhone'");
                                    //
                                    $weichat = $mysql->query("select COUNT(*) as num from `user` WHERE `day` like '{$data['day']}%' and `openid`!='null'");
                                    print <<<table
        <tr>
          <td>{$data['day']}</td>
     	  <td>{$count[0]['num']}</td>
     	  <td>{$android[0]['num']}</td>
		  <td>{$iPhone[0]['num']}</td>
		  <td>{$weichat[0]['num']}</td>
        </tr>
table;
                                } ?>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div class="tab-pane fade" id="profile">
                    </div>
                </div>

            </div>

        </div>
    </div>


</div>

<footer>
    <hr>

    <p class="pull-right"><!--power by right--></p>


    <p><!--power by --></p>
</footer>
<script src="lib/bootstrap/js/bootstrap.js"></script>
<script language="JavaScript">
    function del_id(id) {
        if (confirm("删除是不可恢复的，你确认要删除吗？")) {
            location.href = "?del_id=" + id;

        } else {
            return false;
        }
    }
</script>


</body>
</html>